package com.itheima.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * @Author：武鑫鹏
 * @Project：springboot-aop-quickstart
 * @Date：2024/5/23 15:57
 * @Filename：MyAspect6
 */
@Slf4j
@Component
@Aspect
public class MyAspect6 {

    @Pointcut("@annotation(com.itheima.anno.MyLog)")
    private void pointcut() {}

    @Before("pointcut()")
    public void before(JoinPoint joinPoint) {
        log.info(joinPoint.getSignature().getName() + "MyAspect6 -》 before...");
    }

    @After("pointcut()")
    public void after(JoinPoint joinPoint) {
        log.info(joinPoint.getSignature().getName() + "MyAspect6 -》 after...");
    }

    @Around("pointcut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {

        String name = joinPoint.getTarget().getClass().getName();
        log.info("目标类名: {}",name);

        String methodName = joinPoint.getSignature().getName();
        log.info("目标方法名: {}",methodName);

        Object[] args = joinPoint.getArgs();
        log.info("目标方法参数: {}", Arrays.toString(args));

        // log.info(joinPoint.getSignature().getName() + "MyAspect6 -》 around before...");
        Object result = joinPoint.proceed();
        // log.info(joinPoint.getSignature().getName() + "MyAspect6 -》 around after...");
        return result;
    }
}
